package com.jastar.android.test.base;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Spinner;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import com.jastar.android.test.R;
import com.jastar.android.test.base.adapter.ImagePagerAdapter;
import com.jastar.android.test.base.broadcast.AlarmReceiver;

public class SeniorWidgetActivity extends AppCompatActivity implements View.OnClickListener {

    private static final int[] IMAGES = {R.drawable.pic_character_nezha, R.drawable.pic_character_aobing, R.drawable.pic_character_spiderman};
    private static final String[] STARS = {"水星", "金星", "地球", "火星"};
    private AlarmReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_senior_widget);

        //下拉选择(如果更复杂的选项例如图文，需要用到SimpleAdapter或者BaseAdapter)
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.item_select, STARS);
        Spinner widget_spinner = findViewById(R.id.widget_spinner);
        widget_spinner.setPrompt("请选择行星：");
        widget_spinner.setAdapter(adapter);
        //widget_spinner.setOnItemSelectedListener(this);

        //列表
        ListView widget_list = findViewById(R.id.widget_list);
        widget_list.setAdapter(adapter);

        //表格
        GridView widget_grid = findViewById(R.id.widget_grid);
        widget_grid.setAdapter(adapter);

        //翻页(可扩展加入标签栏PagerTabStrip)
        ImagePagerAdapter imageAdapter = new ImagePagerAdapter(this, IMAGES);
        ViewPager widget_pager = findViewById(R.id.widget_pager);
        widget_pager.setAdapter(imageAdapter);

        //定时广播
        findViewById(R.id.button_1).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        receiver.sendAlarm(getApplicationContext());
    }

    @Override
    protected void onStart() {
        super.onStart();
        receiver = new AlarmReceiver();
        receiver.register(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        receiver.unregister(this);
    }

}